package com.starblink.brand.search.ui

import androidx.fragment.app.FragmentActivity
import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmPageDef
import com.starblink.brand.databinding.CellBrandSearchEmptyBinding
import com.starblink.brand.databinding.CellBrandSearchRecommendTitleBinding
import com.starblink.brand.databinding.CellSimpleProductCardBrandBinding
import com.starblink.brand.search.bean.RvNoDataEntry
import com.starblink.brand.search.bean.RvProductWapper
import com.starblink.brand.search.bean.RvRecommendTitleEntry
import com.starblink.rocketreserver.fragment.ProductF


/**
 * 列表项：搜索结果为空视图
 */
class SearchEmptyCell(
    binding: CellBrandSearchEmptyBinding,
) : BaseBindingVH<RvNoDataEntry, CellBrandSearchEmptyBinding>(binding = binding) {
//    init {
//        (itemView.layoutParams as StaggeredGridLayoutManager.LayoutParams).apply {
//            isFullSpan = true
//        }
//    }

    override fun onBind(model: RvNoDataEntry, position: Int) {
    }
}

/**
 * 列表项：推荐商品标题视图
 */
class RecommendTitleCell(
    binding: CellBrandSearchRecommendTitleBinding,
) : BaseBindingVH<RvRecommendTitleEntry, CellBrandSearchRecommendTitleBinding>(binding = binding) {

    override fun onBind(model: RvRecommendTitleEntry, position: Int) {
    }
}

/**
 * 列表项：商品卡片
 */
class ProductCardCell(
    val activity: FragmentActivity,
    binding: CellSimpleProductCardBrandBinding,
    val brandName: String,
    val searchProducts: ArrayList<Any>, // 搜索商品结果
    val searchKeyword: String, // 搜索关键字
) : BaseBindingVH<RvProductWapper, CellSimpleProductCardBrandBinding>(binding) {

    override fun onBind(model: RvProductWapper, position: Int) {
        // 埋点参数
        val searchResultEmpty: Boolean
        var trackPosition = position
        if (searchProducts.isNotEmpty() && searchProducts.first() is RvNoDataEntry) {
            // 店铺搜索空视图，推荐商品
            searchResultEmpty = true
            trackPosition -= 2 //position减去头部视图
            if (trackPosition < 0) {
                trackPosition = 0
            }
        } else {
            searchResultEmpty = false
        }
        binding.card.bindProduct(
            activity = activity,
            position = trackPosition,
            productWapper = model,
            trackPage = SpmPageDef.BrandSearchPage,
            brandName = brandName,
            searchTerm = searchKeyword,
            searchResultEmpty = searchResultEmpty
        )
    }
}










